//
//  LookHBSimpleTableViewCell.m
//  FMSManager
//
//  Created by hongbao.cui on 15-3-9.
//  Copyright (c) 2015年 hongbao.cui. All rights reserved.
//

#import "LookHBSimpleTableViewCell.h"

@implementation LookHBSimpleTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        textBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"word-normal.png"] forState:UIControlStateNormal];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"word-hover.png"] forState:UIControlStateHighlighted];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"word-hover.png"] forState:UIControlStateSelected];
        [textBtn setSelected:YES];
        [textBtn setFrame:CGRectMake(25, 0, 24.0, 22.0)];
        [self addSubview:textBtn];
        
//        UIButton *draftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [draftBtn setBackgroundImage:[UIImage imageNamed:@"painter-normal.png"] forState:UIControlStateNormal];
//        [draftBtn setBackgroundImage:[UIImage imageNamed:@"painter-hover.png"] forState:UIControlStateHighlighted];
//        [draftBtn setBackgroundImage:[UIImage imageNamed:@"painter-hover.png"] forState:UIControlStateSelected];
//        [draftBtn setFrame:CGRectMake(60, 0, 23.0, 23.0)];
//        [draftBtn addTarget:self action:@selector(draftBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:draftBtn];
        [self initInputView];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}
-(void)initInputView{
    if (!inputTextView) {
        inputTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 25, FMSCREENWIDTH-40, FMSCREENHEIGHT/3)];
    }
   UIImageView *imageView1 = (UIImageView *)[inputTextView viewWithTag:10];
    if (imageView1) {
        [imageView1 removeFromSuperview];
    }
    [inputTextView removeFromSuperview];
    inputTextView.text = @"";
    [inputTextView setReturnKeyType:UIReturnKeyDone];
    [inputTextView setTextContainerInset:UIEdgeInsetsMake(15, 10, 0, 0)];
    [inputTextView setUserInteractionEnabled:NO];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:[inputTextView bounds]];
    UIImage *bgImage = [[UIImage imageNamed:@"Exercises-bj.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 40, 10, 10)];
    imageView.image = bgImage;
    [imageView setTag:10];
    [inputTextView addSubview:imageView];
    [inputTextView sendSubviewToBack:imageView];
    [self addSubview:inputTextView];
}
-(void)setReloadData:(NSDictionary *)dict{
    NSString *userAnswerImage = [dict objectForKey:@"userAnswerImage"];
    NSString *user_answer = [dict objectForKey:@"user_answer"];
    NSString *paper_id = [dict objectForKey:@"paper_id"];
    if (!userAnswerImage||[userAnswerImage isEqualToString:@"0"]||[userAnswerImage isEqualToString:@""]||[userAnswerImage isEqualToString:@"(null)"]) {
        [self initInputView];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"word-normal.png"] forState:UIControlStateNormal];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"word-hover.png"] forState:UIControlStateHighlighted];
        if ([user_answer isEqualToString:@"(null)"]) {
            user_answer= @"";
        }
        [textBtn setBackgroundImage:[UIImage imageNamed:@"word-hover.png"] forState:UIControlStateSelected];
        inputTextView.text = user_answer;
    }else if([userAnswerImage isEqualToString:@"1"]){
        [textBtn setBackgroundImage:[UIImage imageNamed:@"painter-normal.png"] forState:UIControlStateNormal];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"painter-hover.png"] forState:UIControlStateHighlighted];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"painter-hover.png"] forState:UIControlStateSelected];
        UIImageView *iconImageView = (UIImageView *)[inputTextView viewWithTag:10];
        NSString *path = [NSString stringWithFormat:@"%@/%@/image/%@",FMPAPERSAVE_PATH,paper_id,user_answer];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        [iconImageView setImage:image];
    }else if([userAnswerImage isEqualToString:@"2"]){
        [textBtn setBackgroundImage:[UIImage imageNamed:@"photo-normal.png"] forState:UIControlStateNormal];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"photo-hover.png"] forState:UIControlStateHighlighted];
        [textBtn setBackgroundImage:[UIImage imageNamed:@"photo-hover.png"] forState:UIControlStateSelected];
        UIImageView *iconImageView = (UIImageView *)[inputTextView viewWithTag:10];
        NSString *path = [NSString stringWithFormat:@"%@/%@/image/%@",FMPAPERSAVE_PATH,paper_id,user_answer];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        [iconImageView setImage:image];
    }
}
@end
